/**
* @Title: caseHandle_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
* Company:中国平安
* ex-xieqi001
* @Project HIMS-FWA
* @date 2014年11月11日 下午4:43:38
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('TransactorleCtrl', ['$scope','$stateParams','CommunityService','BaseURL','Modal','TransactorleService',
	                                function($scope,$stateParams,CommunityService,baseUrl,Modal,TransactorleService){
		//待调查
		$scope.investigated = {
				include: baseUrl + 'views/hcpms/workingArea/audit/transactorle/investigated_view.html'
		};
		//调查待复核
		$scope.accounts = {
				include: baseUrl + 'views/hcpms/workingArea/audit/transactorle/accounts_view.html'
		}; 
		//待稽核
		$scope.audit = {
				include: baseUrl + 'views/hcpms/workingArea/audit/transactorle/audit_view.html'
		}; 
		//稽核待复核
		$scope.auditReview = {
				include: baseUrl + 'views/hcpms/workingArea/audit/transactorle/auditReview_view.html'
		}; 
	
		
		//获取待处理事件的数量以及显示进度条长度
		TransactorleService.getUnprocessedQuestion().success(function(res){
			//判断最大值为100% 其他占比是占最大值的百分之多少
			var value = CommunityService.compareValue(res.investigatedNum,res.accountsNum);
			
			var value2 = CommunityService.compareValue(res.auditNum,res.auditReviewNum);
			
			var num =  CommunityService.compareValue(value,value2);
			
			$scope.investigated.proportion = (res.investigatedNum/num)*100;
			$scope.accounts.proportion = (res.accountsNum/num)*100;
			$scope.audit.proportion = (res.auditNum/num)*100;
			$scope.auditReview.proportion = (res.auditReviewNum/num)*100;
			
			$scope.investigated.num = res.investigatedNum;
			$scope.accounts.num = res.accountsNum;
			$scope.audit.num = res.auditNum;
			$scope.auditReview.num = res.auditReviewNum;
		}); 
		$scope.barOption = {
				grid:{
					x:30,
					y:40,
					x2:10,
					y2:40,
					borderColor:'#fff'
				},
				title : {
			        text: '事件案件汇总',
			        x: 'left'
			    },
				xAxis : [{
		             type : 'category',
		             boundaryGap: true,
		             data : ['14-01']
		         }],
		         series:[],
		         color:['#56C8E3','#F4AF74']
		};
		//获取echarts 数据
		TransactorleService.getQuestionCount().success(function(res){
			$scope.barOption.xAxis = [{
	             type : 'category',
	             boundaryGap: true,
	             data : res.dateList
	         }];
			
			var barSeries  = [];
			barSeries.push({
				name:'事件调查',
				type:'bar',
				data:res.investigatedData
			},{
				name:'稽核案件',
				type:'bar',
				data:res.auditData
			});
			$scope.barOption.series = barSeries; 
		});
		
		//选中div
		$scope.selectedDiv = function (selected){
			$scope.selected = selected;
		}
		
		//默认选中一个div
		if ($stateParams.urlFlag) {
			if ($stateParams.urlFlag == '5') {
				$scope.selected = $scope.accounts;
			}
			else if ($stateParams.urlFlag == '2') {
				$scope.selected = $scope.audit;
			}else if ($stateParams.urlFlag == '3') {
				$scope.selected = $scope.auditReview;
			}
			else {
				$scope.selected = $scope.investigated;
			}
		}
		else {
			$scope.selected = $scope.investigated;
		}
	
	}]).controller('InvestigatedCtrl', ['$scope','FwaTabsetService','Modal','TransactorleService',
	                               function($scope,FwaTabsetService,Modal,TransactorleService){
		$scope.columns = [
		      			{
		    				label : '事件号',
		    				map : 'problemNo',
		    				width : '10%',
		    				cellTemplate:'<a  ng:bind="data.problemNo" ng-click="queryByProblemNo(data)"></a>'
		    			},{
		    				label : '事件时间段',
		    				map : 'periodDate',
		    				width : '15%'
		    			}, {
		    				label : '事件要点',
		    				map : 'keyPoint',
		    				width : '20%'
		    			}, {
		    				label : '来源方式',
		    				map : 'sourceTypeDesc',
		    				width : '10%'
		    			}, {
		    				label : '提交日期',
		    				map : 'submitDate',
		    				width : '15%'
		    			}, {
		    				label : '关联案件号',
		    				map : 'caseCode',
		    				width : '10%'
		    			}, {
		    				label : '状态',
		    				map : 'statusName',
		    				width : '10%'
		    			}, {
		    				label : '操作',
		    				map : 'operations',
		    				width : '10%',
		    				cellClass:'text-center',
		    				cellTemplate:'<a  ng-click="operation(data)">调查</a>'
		    			}
		    		];
		
		var code = '4';
		//查询
		function query() {
			
			TransactorleService.queryProblemTaskList(code).success(function(res){
				if (res) {
	        		$scope.tableData = res.result;
	        		$scope.totalCount = res.total;
	    		}
			});
		}
		query();
		
		//查看
		$scope.queryByProblemNo = function(data) {
			FwaTabsetService.selectTab('problemDetailView.detail',{problemCode:data.problemNo,problemStatus:data.problemStatus},false);
		}
		
		//调查
		$scope.operation = function(data){
			if(data.rollbackFlag==1){
				FwaTabsetService.selectTab('problemResearch.auditBackDispatchAddResult',{problemNo:data.problemNo,urlFlag:code},false);
			}else{
				FwaTabsetService.selectTab('problemResearch.auditDispatchResult',{problemNo:data.problemNo,urlFlag:code},false);
			}
		}
	
	}]).controller('AccountsCtrl', ['$scope','FwaTabsetService','Modal','TransactorleService',
	                               function($scope,FwaTabsetService,Modal,TransactorleService){
		$scope.columns = [
			      			{
			    				label : '事件号',
			    				map : 'problemNo',
			    				width : '10%',
			    				cellTemplate:'<a  ng:bind="data.problemNo" ng-click="queryByProblemNo(data)"></a>'
			    			},{
			    				label : '事件时间段',
			    				map : 'periodDate',
			    				width : '15%'
			    			}, {
			    				label : '事件要点',
			    				map : 'keyPoint',
			    				width : '20%'
			    			}, {
			    				label : '来源方式',
			    				map : 'sourceTypeDesc',
			    				width : '10%'
			    			}, {
			    				label : '提交日期',
			    				map : 'submitDate',
			    				width : '15%'
			    			}, {
			    				label : '关联案件号',
			    				map : 'caseCode',
			    				width : '10%'
			    			}, {
			    				label : '状态',
			    				map : 'statusName',
			    				width : '10%'
			    			}, {
			    				label : '操作',
			    				map : 'operations',
			    				width : '10%',
			    				cellClass:'text-center',
			    				cellTemplate:'<a  ng-click="operation(data)">复核</a>'
			    			}
			    		];
		var code = '5';
		//查询
		function query() {
			TransactorleService.queryProblemTaskList(code).success(function(res){
				if (res) {
	        		$scope.tableData = res.result;
	        		$scope.totalCount = res.total;
	    		}
			});
		}
		
		query();
		
		//查看
		$scope.queryByProblemNo = function(data) {
			FwaTabsetService.selectTab('problemDetailView.detail',{problemCode:data.problemNo,problemStatus:data.problemStatus},false);
		}
		
		//复核
		$scope.operation = function(data){
			if(data.rollbackFlag==1){
				FwaTabsetService.selectTab('problemResearch.auditBackDispatchReviewResult',{problemNo:data.problemNo,urlFlag:code},false);
			}else{
				FwaTabsetService.selectTab('problemResearch.auditDispatchReviewResult',{problemNo:data.problemNo,urlFlag:code},false);
			}
		}
	
	}]).controller('AuditCtrl', ['$scope','FwaTabsetService','Modal','TransactorleService',
	                               function($scope,FwaTabsetService,Modal,TransactorleService){
			$scope.columns = [
			          		{
			          			label : '案件号',
			          			map : 'caseCode',
			          			width : '10%',
			          			 cellTemplate:'<a  ng:bind="data.caseCode" ng-click="queryByProblemNo(data)"></a>'},
			          		{
			          			label : '机构名称',
			          			map : 'orgName',
			          			width : '15%'
			          		}, {
			          			label : '受理时间',
			          			map : 'auditDate',
			          			width : '17%'
			          		}, {
			          			label : '不合理费用',
			          			map : 'totalDeduction',
			          			width : '10%'
			          		}, {
			          			label : '告知时间',
			          			map : 'notifyDate',
			          			width : '15%'
			          		}, {
			          			label : '机构确认时间',
			          			map : 'affirmDate',
			          			width : '15%'
			          		}, {
			          			label : '案件状态',
			          			map : 'statusName',
			          			width : '10%'
			          		}, {
			          			label : '操作',
			          			map : 'operation',
			          			width : '8%',
			          			cellClass:'text-center',
			          			cellTemplate:'<a  ng-click="operation(data);">稽核</a>'
			          		}
			          	];
		var code = '2';
		//查询
		function query() {
			
			TransactorleService.queryCaseTaskList(code).success(function(res){
				if (res) {
	        		$scope.tableData = res.result;
	        		$scope.totalCount = res.total;
	    		}
			});
		}
		query();
		
		//查看
		$scope.queryByProblemNo = function(data) {
			FwaTabsetService.selectTab('caseDetailView.detail',{problemCode:data.relatedCode,caseCode:data.caseCode},false);
		}
		
		//稽核
		$scope.operation = function(data){
			if(data.rollbackFlag==1){
				FwaTabsetService.selectTab('caseAudit.caseAuditBackProject',{caseCode:data.caseCode,problemNo:data.relatedCode,urlFlag:code},false);
			}else{
				FwaTabsetService.selectTab('caseAudit.caseAuditProject',{caseCode:data.caseCode,problemNo:data.relatedCode,urlFlag:code},false);
			}
		}
	
	}]).controller('AuditReviewCtrl', ['$scope','FwaTabsetService','Modal','TransactorleService',
	                               function($scope,FwaTabsetService,Modal,TransactorleService){
		$scope.columns = [
		          		{
		          			label : '案件号',
		          			map : 'caseCode',
		          			width : '10%',
		          			 cellTemplate:'<a  ng:bind="data.caseCode" ng-click="queryByProblemNo(data)"></a>'},
		          		{
		          			label : '机构名称',
		          			map : 'orgName',
		          			width : '15%'
		          		}, {
		          			label : '受理时间',
		          			map : 'auditDate',
		          			width : '17%'
		          		}, {
		          			label : '不合理费用',
		          			map : 'totalDeduction',
		          			width : '10%'
		          		}, {
		          			label : '告知时间',
		          			map : 'notifyDate',
		          			width : '15%'
		          		}, {
		          			label : '机构确认时间',
		          			map : 'affirmDate',
		          			width : '15%'
		          		}, {
		          			label : '案件状态',
		          			map : 'statusName',
		          			width : '10%'
		          		}, {
		          			label : '操作',
		          			map : 'operation',
		          			width : '8%',
		          			cellClass:'text-center',
		          			cellTemplate:'<a  ng-click="operation(data);">复核</a>'
		          		}
		          	];
		var code = '3';
		//查询
		function query() {
			
			TransactorleService.queryCaseTaskList(code).success(function(res){
				if (res) {
	        		$scope.tableData = res.result;
	        		$scope.totalCount = res.total;
	    		}
			});
		}
		
		query();
		
		//查看
		$scope.queryByProblemNo = function(data) {
			FwaTabsetService.selectTab('caseDetailView.detail',{problemCode:data.relatedCode,caseCode:data.caseCode},false);
		}
		
		//复核
		$scope.operation = function(data){
			if(data.rollbackFlag==1){
				FwaTabsetService.selectTab('caseAudit.caseReviewBackProject',{caseCode:data.caseCode,problemNo:data.relatedCode,urlFlag:code},false);
			}else{
				FwaTabsetService.selectTab('caseAudit.caseReviewProject',{caseCode:data.caseCode,problemNo:data.relatedCode,urlFlag:code},false);
			}
		}
	
	}]);
})();
